﻿// Copyright (c) 2013 Klimov Ivan 
// Saint Petersburg State University
//
module BrahmaEigenCFA.StaticData

open System.IO
open System.Diagnostics

let printfStore (store:int[]) row column = 
    for i in 0..(row - 1) do
        printf "%d. " i
        for j in 0..(column - 1) do
            printf "%d " store.[i*column + j]
        printf "\n"

let readMapInt (path:string) =
    let lines = File.ReadAllLines path
    lines.[0].Split() |> Array.map int

let readMapFloat (path:string) =
    let lines = File.ReadAllLines path
    lines.[0].Split() |> Array.map float

//initialization all scales
let scales = readMapInt "scales.txt"
let scaleCall = scales.[0]
let scaleLam = scales.[1]
let scaleVar = scales.[2]
let scaleExp = scaleLam + scaleVar
let scaleM = (int ((float (scaleLam)/100.0)*4.0*3.0)) + 2

printf "scaleM = %d" scaleM

let pathToFun = "Fun.txt"
let pathToArg1 = "Arg1.txt"
let pathToArg2 = "Arg2.txt"

let initArrayGpu (path:string) = 
    let arrayReading:int[] = path |> readMapInt
    let gpuArray = Array.init scaleCall (fun index -> arrayReading.[index])
    gpuArray

//Static matrix
let Fun  = initArrayGpu pathToFun
let Arg1 = initArrayGpu pathToArg1
let Arg2 = initArrayGpu pathToArg2

//initialization Store on CPU
let initStore = Array2D.init scaleExp scaleM (fun i j -> if i < scaleVar 
                                                            then (if j < 1 
                                                                  then 1.0 
                                                                  else -1.0) 
                                                            else (if j < 1 
                                                                  then 2.0 
                                                                  else (if j = 1 
                                                                        then ((float i) - (float scaleVar) + 1.0) 
                                                                        else -1.0)))
//copy Store on GPGPU
let Store = initStore
